package com.zhengqing.design.action.strategy._01.service.impl;

import com.zhengqing.design.action.strategy._01.model.FullDiscountCouponBO;
import com.zhengqing.design.action.strategy._01.service.ICouponCalStrategy;

import java.math.BigDecimal;

/**
 * <p> 满减券 </p>
 *
 * @author zhengqingya
 * @description
 * @date 2022/12/16 11:16
 */
public class FullDiscountCouponCalStrategy implements ICouponCalStrategy<FullDiscountCouponBO> {
    @Override
    public BigDecimal calPrice(BigDecimal price, FullDiscountCouponBO couponInfo) {
        return price.compareTo(couponInfo.getThresholdPrice()) > 0
                // 如果总金额 > 满减门槛 则 减去优惠面额
                ? price.subtract(couponInfo.getDiscountPrice())
                : price;
    }
}